//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2002-2006
//
// 'Map properties' dialog.
//

# include "StdAfx.h"
# include "Resource.h"
# include "MapProperties.h"
# include "Map.h"
# include "GarminTypes.h"
# include "NavitelTypes.h"
# include "Load.h"
# include "Globals.h"

void ShowMapProperties (HWND _hWnd) {
	if (g_bLoading)
		return;

	bool bExtras;
	bool bGarmin;
	{
		CCritSec::CLock lock (g_cs);
		bGarmin = g_map.pTypeSet == & g_tsGarmin;
		bExtras = g_map.pTypeSet == & g_tsGarmin || g_map.pTypeSet == & g_tsNavitel;
	}

	// Prepare pages.
	const size_t c_cPages = 8;
	PROPSHEETPAGE pshp [c_cPages];
	::memset (pshp, 0, sizeof (pshp));
	size_t cPage;
	for (cPage = 0; cPage < c_cPages; ++ cPage) {
		pshp [cPage].dwSize    = sizeof (PROPSHEETPAGE);
		pshp [cPage].dwFlags   = PSP_DEFAULT;
		pshp [cPage].hInstance = g_hResInst;
	}
	cPage = 0;

	pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_HEADER);
	pshp [cPage].pfnDlgProc  = _MapHeaderProc;
	++ cPage;

	pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_LEVELS);
	pshp [cPage].pfnDlgProc  = _MapLevelsProc;
	++ cPage;

	if (bGarmin) {
		pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_CGPSMAPPER);
		pshp [cPage].pfnDlgProc  = _MapCGPSMapperProc;
		++ cPage;
	}

	pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_BOUNDS);
	pshp [cPage].pfnDlgProc  = _MapRectBounds;
	++ cPage;

	pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_STATISTICS);
	pshp [cPage].pfnDlgProc  = _MapStatisticsProc;
	++ cPage;

	pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_SOURCE);
	pshp [cPage].pfnDlgProc  = _MapSourceProc;
	++ cPage;

	if (bExtras) {
		pshp [cPage].pszTemplate = MAKEINTRESOURCE (IDD_MAP_EXTRAS);
		pshp [cPage].pfnDlgProc  = _MapExtrasProc;
		++ cPage;
	}

	// Prepare header.
	PROPSHEETHEADER psh;
	::memset (& psh, 0, sizeof (psh));
	psh.dwSize     = sizeof (psh);
	psh.dwFlags    = PSH_PROPSHEETPAGE;
	psh.hwndParent = g_hWnd;
	psh.hInstance  = g_hResInst;
	psh.nPages     = cPage;
	psh.nStartPage = 0;
	psh.ppsp       = pshp;
	psh.pszCaption = "Map Properties";

	::PropertySheet (& psh);
}

